package cn.jly.flink.source2sink.datastream.source;

import cn.jly.flink.entity.SensorReading;
import org.apache.commons.lang3.RandomUtils;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.util.ArrayList;

/**
 * @PackageName cn.jly.flink.source2sink.datastream
 * @ClassName FromCollectionSource
 * @Description 集合source
 * @Author 姬岚洋
 * @Date 2021/1/26 下午 3:35
 */
public class FromCollectionSource {
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        final ArrayList<SensorReading> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            list.add(new SensorReading(String.valueOf(i), System.currentTimeMillis(), RandomUtils.nextDouble(0d, 100d)));
        }

        env.fromElements(list)
                .print("sensor");

        env.fromElements(1, 2, 3, 4)
                .print("int");

        env.execute("FromCollectionSource");
    }
}
